package com.person.leetcode.editor.cn;

import java.util.Arrays;

/**
  * 462.最少移动次数使数组元素相等 II
  * 2022-05-19 11:22:11
**/
public class Sequence_0462_MinimumMovesToEqualArrayElementsIi {
    public static void main(String[] args) {
        Solution solution = new Sequence_0462_MinimumMovesToEqualArrayElementsIi().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
        //排序,算中间值
    public int minMoves2(int[] nums) {
        Arrays.sort(nums);
        int index = (nums.length - 1) / 2;
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            res += Math.abs(nums[i] - nums[index]);
        }
        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
